package cn.bgs.service.impl;

import cn.bgs.dao.GradeMapper;
import cn.bgs.dao.examMapper;
import cn.bgs.exception.PhoenixException;
import cn.bgs.pojo.*;
import cn.bgs.service.TeacherService;
import org.apache.ibatis.annotations.Param;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.constructor.DuplicateKeyException;

import java.util.Calendar;
import java.util.List;

/**
 * @ProjectName: beisheng
 * @Package: cn.bgs.service.impl
 * @ClassName: TeacherServiceImpl
 * @Author: Administrator
 * @Description:
 * @Date: 2021/7/21 0021 20:41
 * @Version: 1.0
 */
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private GradeMapper gradeMapper;
    @Autowired
    private examMapper examMapper;
    Logger log = LogManager.getLogger();

    @Override
    public Integer gradeAddStu(Integer[] ids, String gradeId, String gradeName) throws PhoenixException {
        try{
            int count=0;
            for(int i=0;i<ids.length;i++){
                StudentGradeRelation sgr=new StudentGradeRelation();
                sgr.setStudentId(ids[i].toString());
                sgr.setGradeGradeId(gradeId);
                sgr.setGradeGradeName(gradeName);
                sgr.setDeleteFlag("0");

                //获取时间
                Calendar now = Calendar.getInstance();
                sgr.setCreateTime(now.getTime());
                sgr.setUpdateTime(now.getTime());

                log.error("gradeMapper.insertGradeStu:::" + sgr);
                count+=gradeMapper.insertGradeStu(sgr);

            }

            return count;
        }catch (DuplicateKeyException e) {

            log.error("gradeMapper.insertGradeStu:::" + e.getMessage());
            throw new PhoenixException("8888", "违反唯一索引");

        }
    }

    @Override
    public List<Grade> findTeacher(String gradeName, String teacherName, String lectureName) {
        return gradeMapper.findTeacher(gradeName,teacherName,lectureName);
    }

    @Override
    public Integer insertTeacher(Grade grade) {
        return gradeMapper.insertTeacher(grade);
    }

    @Override
    public Integer deleteTeacherList(List<Integer> list) {
        return gradeMapper.deleteTeacherList(list);
    }

    @Override
    public List<Classroom> findclassroom() {
        return gradeMapper.findclassroom();
    }

    @Override
    public void insertclassroomClassroomId(String classroomClassroomId) {
        gradeMapper.insertclassroomClassroomId(classroomClassroomId);
    }
    @Override
    public void insertoldClassroomId(String oldclassroomClassroomId) {
        gradeMapper.insertoldclassroomId(oldclassroomClassroomId);
    }

    @Override
    public List<Classroom> classroomId() {
        return gradeMapper.classroomId();
    }

    @Override
    public Integer teacherDelete(Integer pkId) {
        return gradeMapper.teacherDelete(pkId);
    }

    @Override
    public List<Yuangong> itsclassTeacherName() {
        return gradeMapper.itsclassTeacherName();
    }

    @Override
    public Integer updateTeacher(Grade grade) {
        return gradeMapper.updateTeacher(grade);
    }

    @Override
    public List<Jiangshi> itsjiangshi() {
        return gradeMapper.Jiangshi();
    }

    @Override
    public Grade gradeFind(Integer pkId) {
        return gradeMapper.selectByPrimaryKey(pkId);
    }

    @Override
    public Grade gradeFindSel(String gradeName) {
        return gradeMapper.gradeFindSel(gradeName);
    }

    @Override
    public List<exam> findExam() {
        return examMapper.findExam();
    }
}
